package com.shop.seckill.controller;

import com.shop.domain.Order;
import com.shop.entity.Result;
import com.shop.seckill.service.SecKillOrderService;
import com.shop.seckill.utils.AccessLimit;
import com.shop.util.TokenDecode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀订单
 */
@RestController
@RequestMapping("/seckillOrder")
@AccessLimit
public class SecKillOrderController {
    @Autowired
    private SecKillOrderService seckillOrderService;
    @Autowired
    private TokenDecode tokenDecode;

    /**
     * 秒杀下单
     * @param order
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Order order ,@RequestParam String random) {

        boolean add = seckillOrderService.add(order,random);
        if (add) {
            return Result.ok("秒杀下单成功");
        }else {
            return Result.fail("秒杀下单失败");
        }
    }
}
